package com.fzkjjt.storage.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzkjjt.storage.mapper.Storage;
import com.fzkjjt.storage.mapper.StorageMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @program: seata-simple
 * @description:
 * @author: FangZhen
 * @create: 2020-10-14 15:47
 **/
@Service
public class StorageService {

    @Autowired
    private StorageMapper storageMapper;

    public void deduct(String commodifyCode, int count) {
        QueryWrapper<Storage> storageQueryWrapper = new QueryWrapper<>();

        storageQueryWrapper.eq("commodity_code", commodifyCode);

        Storage storage = storageMapper.selectOne(storageQueryWrapper);

        storage.setCount(storage.getCount() - count);

        storageMapper.updateById(storage);
    }
}
